<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>签到咨询师信息页面</title>
<link rel="stylesheet" href="layui/css/layui.css" media="all">


<style>
.layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
	height: 34px;
	line-height: 34px;
	padding: 0 8px;
}
</style>
</head>
<body>
	<div class="layuimini-container">
		<div class="layuimini-main">
			<div class="layui-form" style="margin-top: 20px;" onsubmit="false">
				<div class="layui-form-item">
					<label class="layui-form-label">咨询师姓名:</label>
					<div class="layui-input-inline">
						<input type="text" name="username" id="username"
							placeholder="请输入咨询师姓名" class="layui-input">
					</div>
					
					
						<!-- <label class="layui-form-label">签到状态:</label>
						<div class="layui-input-inline" style="width: 120;">
							<select name="signstate" id="signstate" class="layui-input">
								<option value="">请选择状态</option>
								<option value="1">已签到</option>
								<option value="2">未签到</option>
							</select>
						
					</div> -->
					<button class="layui-btn" id="search" data-type="reload">搜索</button>
				</div>
				
			</div>
			<div>
				<table class="layui-hide" id="test" lay-filter="test"></table>
			</div>
		</div>
	</div>


	<!-- 操作列 -->
	<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="editConsultant">编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delConsultant">删除</a>
		</script>
	<script type="text/html" id="toolbarDemo">
      <!--表头上面引入了 开关  操作-->
  
       进行自动分配咨询师 <input type="checkbox" style="width:30px;" name="state" id="state" lay-skin="switch" lay-text="是|否" lay-filter="sexDemo">
     
    </script>
	<script src="layui/layui.js" charset="utf-8"></script>
	<script src="js/Global.js" type="text/javascript" charset="utf-8"></script>

	<script type="text/html" id="signstateqiandaozhuangtai">
      {{#  if(d.signstate == 1){ }}
          <span style="color: #F581B1;">已签到</span>
      {{#  } else if(d.signstate == 2){ }}
          <span style="color: #1e9fff;">未签到</span>
      {{#  } }}
         </script>
	<script>
		layui
				.use(
						[ 'form', 'table', 'laydate' ],
						function() { //如果只加载一个模块，可以不填数组。如：layui.use('form')
							form = layui.form, table = layui.table;//获取table模块
							var laydate = layui.laydate;
							var $ = layui.jquery;
						
							/*读取开关状态*/
							$.get(globalData.server + 'switch/getState',{},
								function(obj){
									if (obj.data[0].state==1) {
										$("#state").attr("checked",true);
									}
							},"json");
							
							
							
							//执行一个laydate实例
							laydate.render({
								elem : '#Consultanttime', //指定元素
								type : 'datetime',
								theme: 'molv',
								trigger : 'click', //采用click弹出
								calendar : true, //允许显示公历节日
								range : [ '#Consultanttime_min', '#Consultanttime_max' ]
							});
							setTimeout(function(){
							// 渲染表格
							table.render({
										elem : '#test',
										url : globalData.server
												+ 'public/getSignConsultant',
										toolbar : '#toolbarDemo', //开启头部工具栏
										where : {
											method : 'getAll',
											Consultantname : ''
										},
										method : 'POST',
										cols : [ [
												{
													field : 'signid',
													title : '签到ID',
													fixed : 'left',
													align : 'center',
													sort : true,
													width : 100,
												},
												{
													field : 'username',
													title : '咨询师姓名',
													align : 'center',
													width : 100,
												},
												{
													field : 'signstate',
													title : '签到状态',
													templet : '#signstateqiandaozhuangtai',
													align : 'center',
													width : 100,
												},
												{
													field : 'signtime',
													title : '签到时间',
													templet : "<div>{{!d.signtime?'':layui.util.toDateString(d.signtime, 'yyyy-MM-dd HH:mm:ss')}}</div>",
													align : 'center',
													width : 170,
												},
												{
													field : 'signouttime',
													title : '签退时间',
													templet : "<div>{{!d.signouttime?'':layui.util.toDateString(d.signouttime, 'yyyy-MM-dd HH:mm:ss')}}</div>",
													align : 'center',
													width : 170,
												}, {
													field : 'weight',
													title : '权重排序',
													sort : true,
													align : 'center',
													width : 120,
												}, {
													field : 'message',
													title : '备注',
													align : 'center',
													width : 150,
												}, {
													title : '操作',
													fixed : 'right',
													align : 'center',
													toolbar : '#barDemo',
													width : 180
												} ] ],
										id : 'testReload',
										page : true
							  });
							});
							//是否开启自动分配
							form.on('switch(sexDemo)', function(data) {
								var state = this.checked ? 1 : 2;
								$.get(globalData.server + 'switch/updateState',{
										'state': state
									},function(d){
										if(d.count > 0 && d.data.state == 1) {
												layer.msg("开启自动分配", { icon: 1 });
											} else if(d.count > 0 && d.data.state == 2) {
												layer.msg("关闭自动分配", { icon: 1 });
											} else {
												layer.msg("操作失败！", { icon: 5 });
											}
								},"json");
							});
					        // 监听搜索操作
							$('#search').on('click',function() {
										/* var Consultantstate = $("#Consultantstate").val(); */
										 //执行搜索重载
										table.reload('testReload', {
											where : {
												'signstate' : $("#signstate").val(),
												'username' : $("#username").val()
											}
										});
									});
							//监听表格复选框选择
					        table.on('checkbox(test)', function (obj) {
					            console.log(obj)
					        });

					        table.on('tool(test)', function (obj) {
					            var data = obj.data;
					            if (obj.event === 'editConsultant') {
									//prompt层
											layer.prompt({
												title: '进行修改 ' + data.username + ' 的权重：',
												value: data.weight,
												formType: 0
											}, function(pass, index) {
												if(/^\d+$/.test(pass)){
											      	$.post(globalData.server+ 'public/updateSign', {
														"signid": data.signid,
														"weight": pass
													}, function(data) {
														if(data.count > 0) {
															layer.msg("修改成功", {
																icon: 1,
																time: 3000
															});
														} else {
															layer.msg("修改失败", {
																icon: 2,
																time: 3000
															})
														}
													}, "json");
													window.location.reload();
													layer.close(index);
										    	}else{
										    		layer.msg("请输入数字");
										    	}
											});
					            } else if (obj.event === 'delConsultant') {
					                layer.confirm('真的删除 '+ data.username +' 的签到信息吗?', function(index) {
										$.post(globalData.server+ 'public/deleteSign', {
											"signid" : data.signid
										}, function(res) {
											if(res.data) {
												layer.msg("删除成功", {
													icon: 1,
													time: 3000
												});
												obj.del();
											} else {
												layer.msg("删除失败", {
													icon: 2,
													time: 3000
												})
											}
										}, "json");
										obj.del();
										layer.close(index);
									});
					            }
					        });
						});
	</script>

</body>
</html>